#ifndef __BY_DECODER_H__
#define __BY_DECODER_H__

#pragma once
#include "CCStreamDecoder.h"
#include "CCPacket.h"

NAMESPACE_CC_BY_BEGIN

class Decoder : public CCStreamDecoder
{
public:
	Decoder(){};
	virtual ~Decoder(){};

protected:
	virtual inline int GetHeadLen(const char * data, int len)
	{
		(void)len;
		int  protocol = CCPackete::parse_protocol(data);
		int headlen = CCPackete::parse_head_len(protocol);
		return headlen;
	}

	virtual inline  bool CheckHead(const char * data, int len)
	{
		(void)len;
		return CCPackete::check_head(data);
	}

	virtual inline  int GetPacketLen(const char * data, int len)
	{
		(void)len;
		int pkglen = CCPackete::parse_packet_len(data);
		//if (pkglen < GetHeadLen(data, len) || pkglen >= MAX_PACKET_LEN)
		if (pkglen <= 0 || pkglen >= MAX_PACKET_LEN)
			return -1;
		else
			return pkglen;
	}


};

NAMESPACE_CC_BY_END

#endif